import { Button } from "../../../fl/controls/Button";
import { IToolTipItem } from "../manager/IToolTipItem";
import { IFrUI } from "../core/IFrUI";
import { Global } from "../../gengine/global/Global";
import { ToolTipsManager } from "../manager/ToolTipsManager";
import { GlobalClass } from "../core/GlobalClass";
import { MuiEvent } from "../events/MuiEvent";
import { ObjEventListerTool } from "../utils/ObjEventListerTool";
import { UICompomentPool } from "../utils/UICompomentPool";
import { LibraryEvent } from "../events/LibraryEvent";
import { Caller } from "../../gengine/core/call/Caller";
type int = number;
//class GLoadedButton
    
    export  class GLoadedButton extends Button implements IToolTipItem, IFrUI
    {
        constructor()
        {
            
            super();this.buttonMode = true;
            this.useHandCursor = true;
            setStyle("overSkin", new Object /* flash.display.Bitmap */());
            setStyle("upSkin", new Object /* flash.display.Bitmap */());
            setStyle("downSkin", new Object /* flash.display.Bitmap */());
            setStyle("disabledSkin", new Object /* flash.display.Bitmap */());
            this.addEventListener(flash.events.Event.ADDED_TO_STAGE, this.judgeToolTip);
            this.addEventListener(flash.events.Event.REMOVED_FROM_STAGE, this.judgeToolTip);
            return;
        }

        protected judgeToolTip(arg1: Object /* flash.events.Event */=null): void
        {
            if (arg1 && arg1.type == flash.events.Event.ADDED_TO_STAGE && this.toolTipData || !arg1 && this.toolTipData && Global.stage.contains(this)) 
            {
                ToolTipsManager.register(this);
            }
            else 
            {
                ToolTipsManager.unregister(this);
            }
            return;
        }

        protected getPath(): string
        {
            if (GLoadedButton._getPath == null) 
            {
                return this._resName;
            }
            return GLoadedButton._getPath.call(null, this._resName);
        }

        public get styleName(): string
        {
            return this._resName;
        }

        public set styleName(arg1: string)
        {
            GLoadedButton.addListener();
            if (!arg1) 
            {
                return;
            }
            this._resName = arg1;
            if (GLoadedButton.isResLoaded(this._resName)) 
            {
                this.setStyles();
            }
            else if (GLoadedButton.isResLoading(this._resName)) 
            {
                GLoadedButton._loadCaller.addCall(this._resName, this.setStyles);
            }
            else 
            {
                GLoadedButton._loadCaller.addCall(this._resName, this.setStyles);
                GLoadedButton._aryResLoading.push(this._resName);
                GlobalClass.libaray.loadSWF(this.getPath(), this._resName);
            }
            return;
        }

        protected setStyles(): void
        {
            if (!GlobalClass.hasRes(this._resName + "_upSkin")) 
            {
                return;
            }
            setStyle("overSkin", this.getBimap("_overSkin"));
            setStyle("upSkin", this.getBimap("_upSkin"));
            setStyle("downSkin", this.getBimap("_downSkin"));
            setStyle("disabledSkin", this.getBimap("_disabledSkin"));
            this._isHasInitStyle = true;
            this.dispatchEvent(new MuiEvent(MuiEvent.GLOADEDBUTTON_STYLE_COMPLETE));
            return;
        }

        public get isHasInitStyle(): Boolean
        {
            return this._isHasInitStyle;
        }

        protected getBimap(arg1: string): Object /* flash.display.Bitmap */
        {
            var loc1=this._resName + arg1;
            if (GlobalClass.hasRes(loc1)) 
            {
                return GlobalClass.getBitmap(loc1);
            }
            return GlobalClass.getBitmap(this._resName + "_upSkin");
        }

        public set filterEnabled(arg1: Boolean)
        {
            this.enabled = arg1;
            this.filters = arg1 ? null : [GLoadedButton.colorFilter2];
            return;
        }

        public get toolTipData()
        {
            return this._toolTipData;
        }

        public set toolTipData(arg1)
        {
            this._toolTipData = arg1;
            this.judgeToolTip();
            return;
        }

        public configEventListener(arg1: string, arg2: Function, arg3: Boolean=false, arg4: int=0, arg5: Boolean=false): void
        {
            ObjEventListerTool.addObjEvent(this, arg1, arg2, arg3);
            addEventListener(arg1, arg2, arg3, arg4, arg5);
            return;
        }

        public /* override */ removeEventListener(arg1: string, arg2: Function, arg3: Boolean=false): void
        {
            ObjEventListerTool.removeObjEvent(this, arg1, arg2, arg3);
            super.removeEventListener(arg1, arg2, arg3);
            return;
        }

        public dispose(arg1: Boolean=true): void
        {
            this._isHasInitStyle = false;
            this._resName = "";
            this.extName = "";
            setStyle("overSkin", new Object /* flash.display.Bitmap */());
            setStyle("upSkin", new Object /* flash.display.Bitmap */());
            setStyle("downSkin", new Object /* flash.display.Bitmap */());
            setStyle("disabledSkin", new Object /* flash.display.Bitmap */());
            ObjEventListerTool.delObjEvent(this);
            if (this.parent) 
            {
                this.parent.removeChild(this);
            }
            if (arg1) 
            {
                UICompomentPool.disposeUICompoment(this);
            }
            return;
        }

        /* internal  */static isResLoaded(arg1: string): Boolean
        {
            return GLoadedButton._aryResLoaded.indexOf(arg1) > -1;
        }

        /* internal  */static isResLoading(arg1: string): Boolean
        {
            return GLoadedButton._aryResLoading.indexOf(arg1) > -1;
        }

        public static setGetPath(arg1: Function): void
        {
            GLoadedButton._getPath = arg1;
            return;
        }

        /* internal  */static addListener(): void
        {
            if (!GLoadedButton._isAddLis) 
            {
                GlobalClass.libaray.addEventListener(LibraryEvent.SINGLELOAD_COMPLETE, GLoadedButton.onlibraryCompleteHandler);
                GLoadedButton._isAddLis = true;
            }
            return;
        }

        /* internal  */static onlibraryCompleteHandler(arg1: LibraryEvent): void
        {
            var loc1=String(arg1.data);
            GLoadedButton._loadCaller.call(loc1);
            GLoadedButton._loadCaller.removeCallByType(loc1);
            GLoadedButton._aryResLoaded.push(loc1);
            if (GLoadedButton.isResLoading(loc1)) 
            {
                GLoadedButton._aryResLoading.splice(GLoadedButton._aryResLoading.indexOf(loc1), 1);
            }
            return;
        }

        private static /* const */colorFilter2: Object /* flash.filters.ColorMatrixFilter */=new Object /* flash.filters.ColorMatrixFilter */([0.5086, 0.2094, 0.082, 0, 0, 0.5086, 0.2094, 0.082, 0, 0, 0.5086, 0.2094, 0.082, 0, 0, 0, 0, 0, 1, 0]);

        public /* var */extName: string;

        protected /* var */_resName: string;

        protected /* var */_isHasInitStyle: Boolean=false;

        protected /* var */_toolTipData;

        private static /* var */_loadCaller: Caller;

        private static /* var */_aryResLoaded: Array<any>;

        private static /* var */_aryResLoading: Array<any>;

        private static /* var */_getPath: Function;

        private static /* var */_isAddLis: Boolean=false;
    }

            GLoadedButton._loadCaller = new Caller();
            GLoadedButton._aryResLoaded = new Array<any>();
            GLoadedButton._aryResLoading = new Array<any>();
            GLoadedButton._isAddLis = false;
        